﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[GetDislocation]
	-- Add the parameters for the stored procedure here
	--<@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>, 
	--<@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>
AS
BEGIN
SELECT top 20
			Dislocation.CarNumber, --0
			Dislocation.Weight, --1
			StationArr.Name as StationArr, --2
			Cargo.Name as CargoName, --3
			Dislocation.ConsigneeCode, --4
			Dislocation.CarParkType, --5
			StationDisp.Name as StationDisp,--6
			CarOperation.Name as CarOper,--7
			Dislocation.OperationDateTime,--8
			stationOper.Name as stationOper, --9
			RoadDel.Name as RoadDel, --10
			RoadRec.Name as RoadRec, --11
			Dislocation.TrainIndex, --12
			Dislocation.TrainNumber --13
FROM    Dislocation
			left JOIN  Road as RoadDel ON Dislocation.RoadOfDelivery = RoadDel.Code 
			left JOIN  Road as RoadRec ON Dislocation.RoadOfReception = RoadRec.Code 
			left JOIN Station as  stationArr  ON Dislocation.ArrivalStation = stationArr.Station_ID
			left JOIN Station as stationOper ON Dislocation.OperationStation = stationOper.Station_ID
			left JOIN Station as stationDisp ON Dislocation.DispatchStation = stationOper.Station_ID
			left Join Cargo on Dislocation.CargoCode = Cargo.ShortCode
			--left Join ShipmentClient on Dislocation.ConsigneeCode = ShipmentClient.Code
			left Join CarOperation on Dislocation.OperationCode = CarOperation.Code and CarOperation.OperationType = 0
			


END
